package com.sb.controller;

import com.sb.dao.AreaDao;
import com.sb.entity.Area;
import com.sb.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 小柯
 * @Date 2019/11/24  22:01
 **/

@RestController
@RequestMapping("super")
public class AreaController {


    @Autowired
    private AreaService areaService;

    @GetMapping("listArea")
    public Map<String, Object> listArea(){
        Map<String, Object> modelMap = new HashMap<>();
        List<AreaDao> list = areaService.queryArea();
        modelMap.put("areaList", list);
        return modelMap;

    }
    @GetMapping("getAreaId")
    public Map<String, Object> getAreaId(Integer id){
        Map<String, Object> modelMap = new HashMap<>();
        Area area = areaService.queryAreaById(id);
        modelMap.put("area", area);
        return modelMap;
    }

    @PostMapping("/addArea")
    public Map<String, Object> addArea(@RequestBody Area area){
        Map<String, Object> modelMap = new HashMap<>();
        boolean b = areaService.insertArea(area);
        modelMap.put("success", b);
        return modelMap;
    }

    @PostMapping("updateArea")
    public Map<String, Object> updateArea(@RequestBody Area area){
        Map<String, Object> modelMap = new HashMap<>();
        boolean b = areaService.updateArea(area);
        modelMap.put("success", b);
        return modelMap;
    }

    @GetMapping("deleteArea")
    public  Map<String, Object> deleteArea(Integer areaId){
        Map<String, Object> modelMap = new HashMap<>();
        boolean b = areaService.deleteArea(areaId);
        modelMap.put("success", b);
        return modelMap;
    }

}
